import type { OrderResultType } from '@/types/address'
import type { OrderListParams, OrderListResult, OrderLogisticResult, OrderPreResult, OrderResult } from '@/types/order'
import { http } from '@/utils/http'

export const getOrderApi = () => {
  return http<OrderPreResult>({
    url: '/member/order/pre',
    method: 'GET',
  })
}
/**
 * 立即购买
 * @param data {skuId: string, count: string, addressId?: string}
 * @returns {Promise<OrderPreResult>}
 */

export const getOrderNowApi = (data: { skuId: string; count: string; addressId?: string }) => {
  return http<OrderPreResult>({
    url: '/member/order/pre/now',
    method: 'GET',
    data,
  })
}
/**
 * 立即购买
 * @param data:OrderResultType
 * @returns {Promise<OrderPreResult>}
 */
export const postMemberOrderApi = (data: OrderResultType) => {
  return http<{ id: string }>({
    url: '/member/order',
    method: 'POST',
    data,
  })
}
/**
 * 获取订单详情
 * @param id
 * @returns {Promise<OrderPreResult>}
 */
export const getMemberOrderByIdApi = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}`,
    method: 'GET',
  })
}
export const getBuyAgainOrderApi = (id: string) => {
  return http<OrderPreResult>({
    url: `/member/order/repurchase/${id}`,
    method: 'GET',
  })
}
/**
 * 模拟发货
 * @param id 订单id
 * @returns
 */
export const getConsignmentApi = (id: string) => {
  return http({
    url: `/member/order/consignment/${id}`,
    method: 'GET',
  })
}
/** 确认收货 */
export const putConfirmReceiptApi = (id: string) => {
  return http<OrderResult>({
    url: `/member/order/${id}/receipt`,
    method: 'PUT',
  })
}
/**
 * 获取订单物流信息
 * @param id 订单id
 * @returns
 */
export const getOrderLogisticsApi = (id: string) => {
  return http<OrderLogisticResult>({
    url: `/member/order/${id}/logistics`,
    method: 'GET',
  })
}
/**
 * 删除订单
 * @param id 订单id
 * @returns OrderResult
 */
export const DeleteCancelOrderApi = (data: { ids: string[] }) => {
  return http<OrderResult>({
    url: `/member/order`,
    method: 'DELETE',
    data,
  })
}
/**
 * 取消订单
 * @param id 订单id
 * @returns OrderResult
 */
export const putCancelOrderApi = (id: string, data: { cancelReason: string }) => {
  return http<OrderResult>({
    url: `/member/order/${id}/cancel`,
    method: 'PUT',
    data,
  })
}
/**
 * 获取订单列表
 * @param id 订单id
 * @returns OrderResult
 */
export const getMemberOrderListApi = (data: OrderListParams) => {
  return http<OrderListResult>({
    url: `/member/order`,
    method: 'GET',
    data,
  })
}
